package com.yidao.organization.domain;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.yidao.core.domain.BaseDomainObject;
import com.yidao.user.domain.User;

@Entity
@Table(name="organizations")
@Inheritance(strategy=InheritanceType.JOINED)
public class Organization extends BaseDomainObject{

	private static final long serialVersionUID = 1L;

	protected User createUser;
	
	protected String description;

	protected String name;

	protected Organization parent;

	protected List<Organization> subOrgs = new ArrayList<Organization>();
	
	public Organization() {
	}
	
	@ManyToOne
	@JoinColumn(name="create_user_id")
	public User getCreateUser() {
		return createUser;
	}
	
	@Column(length=255)
	public String getDescription() {
		return description;
	}
	
	@Column(length=100,nullable=false)
	public String getName() {
		return name;
	}
	
	@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	@JoinColumn(name="parent_id")
	public Organization getParent() {
		return parent;
	}
	
	@OneToMany(cascade=CascadeType.ALL)
	@JoinColumn(name="parent_id")
	public List<Organization> getSubOrgs() {
		return subOrgs;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setParent(Organization parent) {
		this.parent = parent;
	}

	public void setSubOrgs(List<Organization> subOrgs) {
		this.subOrgs = subOrgs;
	}
}
